package com.loyi.ams.gateway.hbmis.rest;

import java.util.List;
import java.util.Map; 

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.loyi.cloud.hbmis.api.IQueryService;

@RestController
@RequestMapping("proxy")
public class QueryService implements IQueryService {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	private Logger logger = LoggerFactory.getLogger(this.getClass());

	@Override
	@RequestMapping("query")
	public List<Map<String, Object>> query( String sql) {
		return jdbcTemplate.queryForList(sql);
	}

	@Override
	@RequestMapping("execute")
	public int execute(String sql) {
		try {
			return this.jdbcTemplate.update(sql);
		} catch (Exception ex) {
			logger.warn("执行失败", ex);
		}
		return 0;
	}

}
